| Conditions | 1 |
| Paths | 1 |
| Total Lines | 103 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | var assert = require('chai').assert, |
||
| 4 | describe('Event', function(){ |
||
| 5 | |||
| 6 | it('Create plain', function(){ |
||
| 7 | assert.instanceOf(GedcomX.Event(), GedcomX.Event, 'An instance of Event is not returned when calling the constructor with new.'); |
||
| 8 | assert.instanceOf(GedcomX.Event(), GedcomX.Event, 'An instance of Event is not returned when calling the constructor without new.'); |
||
| 9 | }); |
||
| 10 | |||
| 11 | it('Create with JSON', function(){ |
||
| 12 | var event = GedcomX.Event({ |
||
| 13 | type: 'http://gedcomx.org/Marriage', |
||
| 14 | date: { |
||
| 15 | formal: '+2002-06-06' |
||
| 16 | }, |
||
| 17 | place: { |
||
| 18 | original: 'Her town, MN' |
||
| 19 | }, |
||
| 20 | roles: [ |
||
| 21 | { |
||
| 22 | person: { |
||
| 23 | resource: 'http://groom' |
||
| 24 | }, |
||
| 25 | type: 'http://gedcomx.org/Participant' |
||
| 26 | } |
||
| 27 | ] |
||
| 28 | }); |
||
| 29 | assert.equal(event.getType(), 'http://gedcomx.org/Marriage'); |
||
| 30 | assert.equal(event.getDate().getFormal(), '+2002-06-06'); |
||
| 31 | assert.equal(event.getPlace().getOriginal(), 'Her town, MN'); |
||
| 32 | assert.equal(event.getRoles().length, 1); |
||
| 33 | assert.equal(event.getRoles()[0].getPerson().getResource(), 'http://groom'); |
||
| 34 | assert.equal(event.getRoles()[0].getType(), 'http://gedcomx.org/Participant'); |
||
| 35 | }); |
||
| 36 | |||
| 37 | it('Create with mixed data', function(){ |
||
| 38 | var event = GedcomX.Event({ |
||
| 39 | type: 'http://gedcomx.org/Marriage', |
||
| 40 | date: GedcomX.Date({ |
||
| 41 | formal: '+2002-06-06' |
||
| 42 | }), |
||
| 43 | place: GedcomX.PlaceReference({ |
||
| 44 | original: 'Her town, MN' |
||
| 45 | }), |
||
| 46 | roles: [ |
||
| 47 | GedcomX.EventRole({ |
||
| 48 | person: { |
||
| 49 | resource: 'http://groom' |
||
| 50 | }, |
||
| 51 | type: 'http://gedcomx.org/Participant' |
||
| 52 | }) |
||
| 53 | ] |
||
| 54 | }); |
||
| 55 | assert.equal(event.getType(), 'http://gedcomx.org/Marriage'); |
||
| 56 | assert.equal(event.getDate().getFormal(), '+2002-06-06'); |
||
| 57 | assert.equal(event.getPlace().getOriginal(), 'Her town, MN'); |
||
| 58 | assert.equal(event.getRoles().length, 1); |
||
| 59 | assert.equal(event.getRoles()[0].getPerson().getResource(), 'http://groom'); |
||
| 60 | assert.equal(event.getRoles()[0].getType(), 'http://gedcomx.org/Participant'); |
||
| 61 | }); |
||
| 62 | |||
| 63 | it('Build', function(){ |
||
| 64 | var event = GedcomX.Event() |
||
| 65 | .setType('http://gedcomx.org/Marriage') |
||
| 66 | .setDate(GedcomX.Date().setFormal('+2002-06-06')) |
||
| 67 | .setPlace(GedcomX.PlaceReference().setOriginal('Her town, MN')) |
||
| 68 | .addRole(GedcomX.EventRole() |
||
| 69 | .setType('http://gedcomx.org/Participant') |
||
| 70 | .setPerson(GedcomX.ResourceReference().setResource('http://groom'))); |
||
| 71 | assert.equal(event.getType(), 'http://gedcomx.org/Marriage'); |
||
| 72 | assert.equal(event.getDate().getFormal(), '+2002-06-06'); |
||
| 73 | assert.equal(event.getPlace().getOriginal(), 'Her town, MN'); |
||
| 74 | assert.equal(event.getRoles().length, 1); |
||
| 75 | assert.equal(event.getRoles()[0].getPerson().getResource(), 'http://groom'); |
||
| 76 | assert.equal(event.getRoles()[0].getType(), 'http://gedcomx.org/Participant'); |
||
| 77 | }); |
||
| 78 | |||
| 79 | it('toJSON', function(){ |
||
| 80 | var data = { |
||
| 81 | type: 'http://gedcomx.org/Marriage', |
||
| 82 | date: { |
||
| 83 | formal: '+2002-06-06' |
||
| 84 | }, |
||
| 85 | place: { |
||
| 86 | original: 'Her town, MN' |
||
| 87 | }, |
||
| 88 | roles: [ |
||
| 89 | { |
||
| 90 | person: { |
||
| 91 | resource: 'http://groom' |
||
| 92 | }, |
||
| 93 | type: 'http://gedcomx.org/Participant' |
||
| 94 | } |
||
| 95 | ] |
||
| 96 | }, event = GedcomX.Event(data); |
||
| 97 | assert.deepEqual(event.toJSON(), data); |
||
| 98 | }); |
||
| 99 | |||
| 100 | it('constructor does not copy instances', function(){ |
||
| 101 | var obj1 = GedcomX.Event(); |
||
| 102 | var obj2 = GedcomX.Event(obj1); |
||
| 103 | assert.strictEqual(obj1, obj2); |
||
| 104 | }); |
||
| 105 | |||
| 106 | }); |